package com.hackordie.commons.hardware.components;

import com.hackordie.constants.EComponentsType;

public abstract class AComponent {

    protected int idComponent;
    protected String componentName;  //TODO cambiar a fromInt en el enum
    protected EComponentsType componentType; // TODO Enumerado
    protected int energyToTurnOn;
    protected boolean started;
    protected int prize;
    
    AComponent(String componentName, EComponentsType ecomponentType, int energyToTurnOn, int prize) {
        this.componentName = componentName;
        this.componentType = ecomponentType;
        this.energyToTurnOn = energyToTurnOn;
        this.started = false;
        this.prize = prize;
    }

    // setters and getters
    public EComponentsType getComponentType() {
        return componentType;
    }

    public String getComponentName() {
        return componentName;
    }

    public void setComponentType(EComponentsType componentType) {
        this.componentType = componentType;
    }

    public int getEnergyToTurnOn() {
        return energyToTurnOn;
    }

    public void setEnergyToTurnOn(int energyToTurnOn) {
        this.energyToTurnOn = energyToTurnOn;
    }

    public boolean isStarted() {
        return started;
    }
 
    
    // functions

    public int getIdComponent() {
        return idComponent;
    }

    public void setIdComponent(int idComponent) {
        this.idComponent = idComponent;
    }

    public int on(int availableEnergy) {
        
        if(started) {
            return (availableEnergy - energyToTurnOn);
        }
        
        if (energyToTurnOn <= availableEnergy) {
            started = true;
            return (availableEnergy - energyToTurnOn);
        }
        return availableEnergy;
    }

    public int off(int availableEnergy) {        
        if (started) {
            started = false;
            return energyToTurnOn + availableEnergy;
        }
        return availableEnergy;
    }

    public int getPrice() {
        return prize;
    }
    
    @Override
    public String toString() {
        
        return idComponent + "-" + 
                componentName + "-" + 
                componentType + "-" + 
                energyToTurnOn + "-" + 
                started + "-" + 
                prize + "-";
    }
}
